package com.zhouyihe.weblog.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName RestTemplateConfig
 * @author: 周益和
 * @qq: 1552951165
 * @date: 2024/8/4
 * @description:
 */
@Configuration
public class RestTemplateConfig {

    @Bean
    public RestTemplate restTemplate(){
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setConnectTimeout(5000); // 连接超时-5秒
        factory.setReadTimeout(5000); // 读取超时-5秒
        return new RestTemplate(factory); // 创建RestTemplate并使用自定义的SimpleClientHttpRequestFactory
    }
}
